package com.hyh.shiyanshiguanli.controller;

import com.hyh.shiyanshiguanli.domain.dto.*;
import com.hyh.shiyanshiguanli.domain.entity.*;
import com.hyh.shiyanshiguanli.domain.result.PageResult;
import com.hyh.shiyanshiguanli.domain.result.Result;
import com.hyh.shiyanshiguanli.domain.vo.DamageVO;
import com.hyh.shiyanshiguanli.service.LabLessonService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * @author hyh
 * @version 1.0
 */
@Slf4j
@RestController
@RequestMapping("/LabLesson")
public class LabLessonController {


    @Autowired
    LabLessonService labLessonService;

    @GetMapping("/page")
    public Result<PageResult> page(PageDTO pageDTO){
        log.info("实验课历史查询{}",pageDTO);

        PageResult result = labLessonService.page(pageDTO);

        return Result.success(result);
    }

    @GetMapping("/Lab")
    public Result<List> selectClassify(){
        log.info("查询所有实验室分类");
        List<LibInformation> libs = labLessonService.selectLab();
        return Result.success(libs);
    }

    @GetMapping("/Instrument")
    public Result<List> selectInstrument(){
        log.info("查询所有仪器分类");
        List<Instrument> instruments = labLessonService.selectInstrument();
        return Result.success(instruments);
    }

    @GetMapping("/Reagent")
    public Result<List> selectReagent(){
        log.info("查询所有试剂分类");
        List<Reagent> reagents = labLessonService.selectReagent();
        return Result.success(reagents);
    }
    @PostMapping("/add")
    public Result addPublicInformation(@RequestBody LabLessonAddDTO labLessonAddDTO){
        log.info("添加labLessonAdd{}",labLessonAddDTO);
        labLessonService.add(labLessonAddDTO);
        return Result.success();
    }

    @GetMapping("/SelectNumById/{id}")
    public Result<Integer> SelectNumById(@PathVariable Integer id){
        log.info("根据id查询最大值{}",id);
        Integer max = labLessonService.selectNumById(id);
        return Result.success(max);
    }
    @GetMapping("/SelectNumByIdReagent/{id}")
    public Result<Integer> SelectNumByIdReagent(@PathVariable Integer id){
        log.info("根据id查询最大值{}",id);
        Integer max = labLessonService.selectNumByIdReagent(id);
        return Result.success(max);
    }

    @GetMapping("/LabSelectById/{id}")
    public Result<List> LabSelectById(@PathVariable Integer id){
        log.info("根据id查询实验室{}",id);
        List <LibInformation> libInformation = labLessonService.LabSelectById(id);
        return Result.success(libInformation);
    }


    @GetMapping("/{id}")
    public Result<DamageVO> selectById(@PathVariable Integer id){
        log.info("根据损坏情况{}",id);
        DamageVO damageVO = labLessonService.selectById(id);
        return Result.success(damageVO);
    }

    @PutMapping("/update")
    public Result updateById(@RequestBody LabLessonUpdateDTO labLessonUpdateDTO){
        log.info("上课结束更新数据数据，id为{}",labLessonUpdateDTO.getId());
        labLessonService.updateById(labLessonUpdateDTO);
        return Result.success();
    }
}
